#include "sqlite.hpp"
#include <cassert>

int select_stu_name_callback(void* arg,int col,char** result,char** fields_name)
{
    std::vector<std::string>* arr = (std::vector<std::string>*)arg;
    arr->push_back(result[0]);
    return 0;
}

int main()
{
    //1.创建/打开库文件
    SqliteHelper helper("./test.db");
    assert(helper.open());
    //2.建表
    const char* ct = "create table if not exists student(sn int primary key,name varchar(32),age int);";
    assert(helper.exec(ct,nullptr,nullptr));
    //3.新增数据，增删查改
    //const char* insert_sql = "insert into student values(1,'jack',18),(2,'six',12),(3,'mono',13);";
    //assert(helper.exec(insert_sql,nullptr,nullptr));

    //const char* update_sql = "update student set name='small six' where name='six';";
    //assert(helper.exec(update_sql,nullptr,nullptr));

    const char* select_sql = "select name from student;";
    std::vector<std::string> arr;

    assert(helper.exec(select_sql,select_stu_name_callback,&arr));

    for(auto& name:arr)
        std::cout<<name<<std::endl;

    //4.关闭数据库
    helper.close();

    return 0;
}